<template>
    <div class="info-collect">
        <Crumb name="Stock In"></Crumb>
        <div class="content">
            <!--<el-button-->
                    <!--type="primary"-->
                    <!--@click="openAdd"-->
            <!--&gt;Add New Export-->
            <!--</el-button>-->
            <Search>
                <el-input
                        v-model="key"
                        size="small"
                        class="input"
                        placeholder="Search By Ship Number"
                        prefix-icon="el-icon-search"
                > </el-input>
                <el-button
                        size="small"
                        type="primary"
                >Search
                </el-button>
            </Search>
            <div class="table-wrapper">
                <el-table
                        :data="visitList"
                        border
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="No"
                            width="60"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="declaration"
                            label="Declaration No"
                            width="180"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="shipNo"
                            label="Ship No"
                            width="150">
                    </el-table-column>
                    <el-table-column
                            prop="declarationDate"
                            label="Date"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="destination"
                            label="Destination"
                            width="150"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="status"
                            label="Status"
                            width="150"
                    >
                    </el-table-column>
                    <el-table-column label="Opr" >
                        <template slot-scope="scope">
                            <el-button
                                    size="mini"
                                    type="primary"
                                    @click="routerTo('/stock-in',scope.id)">Details
                            </el-button>
                            <el-button
                                    size="mini"
                                    type="primary"
                                    @click="routerTo('/error-report',scope.id)">Error report
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="page">
                    <el-pagination background
                                   @current-change="changePage"
                                   layout="prev, pager, next"
                                   :total="total"></el-pagination>
                </div>

            </div>

            <div class="modal-wrapper">
                <el-dialog
                        title="Error"
                        :visible.sync="dialogVisible"
                        width="80%"
                        >

                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px" class="demo-ruleForm">

                        <el-form-item label="Error Detail" prop="errorDetail">
                            <el-input
                                    type="textarea"
                                    :autosize="{ minRows: 4, maxRows: 8}"
                                    v-model="ruleForm.remarks"> </el-input>
                        </el-form-item>
                        <el-form-item label="Error Photo">
                            <el-upload
                                    class="upload-demo"
                                    drag
                                    action="https://jsonplaceholder.typicode.com/posts/"
                                    multiple>
                                <i class="el-icon-upload"></i>
                                <div class="el-upload__text">Drag here，or <em>Click to upload</em></div>
                            </el-upload>
                        </el-form-item>

                    </el-form>


                    <span slot="footer" class="dialog-footer">
                        <el-button @click="dialogVisible = false">Cancel</el-button>
                        <el-button type="primary" @click="submitForm">Confirm</el-button>
                    </span>
                </el-dialog>
            </div>
        </div>
    </div>
</template>

<script>
    import Crumb from '@/components/common/crumb'
    import Search from '@/components/common/search'
    import {mapGetters,mapMutations} from 'vuex'

    export default {
        name: "info-collect",
        data() {
            return {
                checkAll:false,
                visitList: [{
                    declaration : 'LONKING_12_05',
                    shipNo:'VESSEL TEMP 05',
                    declarationDate:'2018-12-05',
                    contractNo: "LONGKING20181205ECDF",
                    status:'unchecked',
                    destination: "SURABAYA",
                    sn:'DE3353333512',
                    en:'R96554422324',
                    model:'TC9600RT',
                    unitType:'EGDGDCG',
                    xxNo:'TRDDC122333',
                    brand:'Trendinao',
                    config:'new customer and good for full payment',
                    id: 2
                }
                ],
                ruleForm: {
                    declaration: '',
                    shipNo: '',
                    declarationDate: '',
                    contractNo: '',
                    bl:'',
                    destination:'',
                    remarks:'',
                    packageList:'',
                    cargoList:'',
                    forMeList:'',
                    id:'',
                },
                rules: {
                    declaration: [
                        { required: true, message: 'Declaration is required', trigger: 'blur' },
                    ],
                    shipNo: [
                        { required: true, message: 'Ship No is required', trigger: 'blur' }
                    ],
                    declarationDate: [
                        {  required: true, message: 'Declaration Date is required', trigger: 'change' }
                    ],
                    contractNo: [
                        {  required: true, message: 'Contract No is required', trigger: 'blur' }
                    ],
                    destination: [
                        {  required: true, message: 'Destination No is required', trigger: 'blur' }
                    ],
                },
                key: '',
                bl:'',
                total: 11,
                dialogVisible:false
            }
        },
        computed:{
            ...mapGetters(['stockId'])
        },
        methods: {
            routerTo(url,id){
                this.setStockId(id);
                this.$router.push(url);

            },
            submitForm(){
                this.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        if (this.id) {
                            alert('m')
                        } else {
                            alert('a')
                        }
                    } else {
                        return false;
                    }
                });
            },
            clear(){
                this.ruleForm.title = '';
                this.ruleForm.customerName = '';
                this.ruleForm.times = '';
                this.ruleForm.address = '';
                this.ruleForm.detail = '';
            },
            openAdd(){
                this.clear();
                this.dialogVisible = true
            },
            openEdit(r){
                this.ruleForm.title = r.title;
                this.ruleForm.customerName = r.customerName;
                this.ruleForm.times = r.times;
                this.ruleForm.address = r.address;
                this.ruleForm.detail = r.detail;
                this.id = r.id;
                this.dialogVisible = true

            },
            changePage(page) {
                alert(page)
            },
            ...mapMutations(['setStockId'])

        },
        components: {
            Crumb, Search
        }
    }
</script>

<style scoped lang="scss">
    .info-collect {
        background: #f6;
        .content {
            text-align: left;
            padding: 20px 0;
            .table-wrapper {
                margin-top: 20px;
            }
            .page {
                text-align: center;
                margin-top: 10px;
            }
        }
    }
</style>